<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="./js/cookie.js"></script>
</head>
<body>
    <div>
        <h3>cookie 模拟单用户登录  </h3>
        <div class="form">
            <div>
                <label for="user">用户名</label>
                <input type="text" id="user" placeholder="请输入用户名">
            </div>
            <div>
                <label for="pass">密码</label>
                <input type="password" id="pass" placeholder="请输入密码">
            </div>
            <div>
                <button id="savebtn" >登录</button>
            </div>
        </div>
    </div>

    <script>
        // 获取元素 
        var userInp = document.getElementById("user")
        var passInp = document.getElementById("pass")

        var savebtn = document.getElementById("savebtn")

        savebtn.onclick = function(){
            var user = userInp.value
            var pass = passInp.value 
            if(user&&pass){
                if(user== getCookie('user')){
                    if(pass == getCookie('pass')){
                        location.href = "https://www.baidu.com"
                    }else{
                        alert("用户名或者密码错误")
                    }
                }else{
                    if(confirm("当前用户没有注册,去注册?")){
                        location.href = './09 cookie模拟单注册.html'
                    }
                }
            }else{
                alert("请先完善登录信息")
            }
        }
    </script>
</body>
</html>